const hotModel = require('../model/hotModel.js');
const filmModel = require('../model/filmModel');
// 分页查询热映电影
module.exports.find = async function(searchObj,page){
    // 分页查询
    let {current,size} = page;
    // 获取数据总数
    let total = await hotModel.countDocuments(searchObj)
    // 根据总数/每页显示数得到总页数
    let totalPage = Math.ceil(total / size);
    // limit是每页显示数，skip通过(当前页-1) * 每页显示得到
    let rows = await hotModel
                .find(searchObj)
                .populate({path:'filmId'})
                .limit(parseInt(size))
                .skip((current - 1) * size);
    return {
        current,size,total,totalPage,rows
    }
}
module.exports.findAll = async function(){
    let data = await hotModel
        .find()
        .populate('filmId');
    return data;
}